import axios from "./axios";

export const getDetailList = async (shop_spu_id: string) => {
  const res = await axios.get(`/api/mall/shop_spu/specification_info/`, { params: { shop_spu_id } })
  const raw = res?.data ?? res
  // 归一化为包含 specification_info/specification_sku_info 的对象
  const normalized =
    (raw && raw.specification_info) ? raw :
    (raw?.data && raw.data.specification_info) ? raw.data :
    (Array.isArray(raw) && raw[0]?.specification_info) ? raw[0] :
    (Array.isArray(raw?.data) && raw.data[0]?.specification_info) ? raw.data[0] :
    {}
  console.log('getDetailList.normalized:', normalized)
  return normalized
}

export const getDetailList1=async(shop_spu_id:string)=>{
    const res=await axios.get(`/api/mall/shop_spu/detail/base/`,{params:{shop_spu_id:shop_spu_id}})
     console.log(res.data);
    return res.data || []
}

export const getDetailList2=async(shop_spu_id:string)=>{
    const res=await axios.get(`/api/mall/shop_spu/detail/tail/`,{params:{shop_spu_id:shop_spu_id}})
     console.log(res.data);
    return res.data || []
}

export const gethomedetail=async(id:string)=>{
    const res=await axios.get(`/api/cooperation/wap/article/${id}/`)
     console.log(res.data);
    return res.data || []
}

export const gethomedetail1=async(id:string)=>{
    const res=await axios.get(`/api/api/search/news/selected_doctor/`,{params:{id:id}})
      console.log(res.data);
    return res.data || []
}